/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       multitexturedmaterial.cpp
 * Author:     karooolek
 * Created on: 2009-03-24
 *
 **********************************************************************************************************************/

#include "multitexturedmaterial.h"

namespace mGameEngine
{
namespace Graphics
{

MultiTexturedMaterial::MultiTexturedMaterial(
        const Texture *texture, const Texture *normalMap, const Texture *specMap,
        const Color &ambient, const Color &diffuse,
        const Color &specular, float shininess, const Color &emmisive) :
    TexturedMaterial(texture, ambient, diffuse, specular, shininess, emmisive),
    _normalMap(normalMap), _specMap(specMap)
{
}

MultiTexturedMaterial::~MultiTexturedMaterial()
{
}

void MultiTexturedMaterial::set() const
{
    // no normal map and specular map, this is textured material
    if(!_normalMap && !_specMap)
    {
        return TexturedMaterial::set();
    }

    // create and compile gpu program
    static GPUProgram gpuProgram(
#include "multitexturedmaterial.vert"
        ,
#include "multitexturedmaterial.frag"
        , true);

    // bind gpu program
    gpuProgram.use();

    // standard material settings
    glMaterialfv(GL_FRONT, GL_AMBIENT, _ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, _diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, _specular);
    glMaterialf(GL_FRONT, GL_SHININESS, _shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, _emissive);

    // textures
    gpuProgram.setTexture("texture", _texture, 0);
    gpuProgram.setTexture("normalMap", _normalMap, 1);
    gpuProgram.setTexture("specMap", _specMap, 2);
}

}
}

